"""
新的护理员模型定义，用于从app_user和app_user_detail表获取护理员信息
"""
from . import db
from sqlalchemy import func
from datetime import datetime


class AppUser(db.Model):
    """用户信息表"""
    __tablename__ = "app_user"
    __table_args__ = {'extend_existing': True}
    user_id = db.Column(db.BigInteger, primary_key=True, comment='用户ID')
    tenant_id = db.Column(db.String(20), nullable=True, default='000000', comment='租户编号')
    dept_id = db.Column(db.BigInteger, nullable=True, comment='部门id')
    role_id = db.Column(db.BigInteger, nullable=True, comment='角色id')
    user_name = db.Column(db.String(30), nullable=False, comment='用户账号')
    nick_name = db.Column(db.String(30), nullable=False, comment='用户昵称')
    user_type = db.Column(db.String(10), nullable=True, default='app_user', comment='用户类型（app_user系统用户）')
    email = db.Column(db.String(50), nullable=True, default='', comment='用户邮箱')
    phone_number = db.Column(db.String(11), nullable=True, default='', comment='手机号码')
    face_url = db.Column(db.String(255), nullable=True, comment='人脸识别地址')
    sex = db.Column(db.String(1), nullable=True, default='0', comment='用户性别（0男 1女 2未知）')
    avatar = db.Column(db.BigInteger, nullable=True, comment='头像地址')
    password = db.Column(db.String(500), nullable=True, default='', comment='密码')
    salt = db.Column(db.String(255), nullable=True, comment='盐字符串')
    system_type = db.Column(db.String(50), nullable=True, comment='系统标识')
    status = db.Column(db.String(1), nullable=True, default='0', comment='帐号状态（0正常 1停用）')
    del_flag = db.Column(db.String(1), nullable=True, default='0', comment='删除标志（0代表存在 2代表删除）')
    login_ip = db.Column(db.String(128), nullable=True, default='', comment='最后登录IP')
    login_date = db.Column(db.DateTime, nullable=True, comment='最后登录时间')
    create_dept = db.Column(db.BigInteger, nullable=True, comment='创建部门')
    create_by = db.Column(db.BigInteger, nullable=True, comment='创建者')
    create_time = db.Column(db.DateTime, nullable=True, comment='创建时间')
    update_by = db.Column(db.BigInteger, nullable=True, comment='更新者')
    update_time = db.Column(db.DateTime, nullable=True, comment='更新时间')
    remark = db.Column(db.String(500), nullable=True, comment='备注')
    task_id = db.Column(db.BigInteger, nullable=True, comment='任务id')
    chat_identity = db.Column(db.String(2), nullable=True, comment='xchat身份（0亲属 1护理员）')

    def __repr__(self):
        return f"<AppUser {self.user_id} {self.user_name} {self.nick_name}>"


class AppUserDetail(db.Model):
    """员工信息表"""
    __tablename__ = "app_user_detail"
    __table_args__ = {'extend_existing': True}
    detail_id = db.Column(db.BigInteger, primary_key=True, comment='主键id')
    name = db.Column(db.String(50), nullable=True, comment='姓名')
    app_user_name = db.Column(db.String(50), nullable=True, comment='app用户名')
    post_id = db.Column(db.BigInteger, nullable=True, comment='岗位')
    age = db.Column(db.Integer, nullable=True, comment='年龄')
    id_card = db.Column(db.String(20), nullable=True, comment='身份证号')
    origin = db.Column(db.String(255), nullable=True, comment='籍贯')
    birthday = db.Column(db.DateTime, nullable=True, comment='生日')
    marriage = db.Column(db.Integer, nullable=True, comment='0未婚1已婚')
    ethnic = db.Column(db.String(10), nullable=True, comment='民族')
    colleges = db.Column(db.String(255), nullable=True, comment='院校')
    specialized = db.Column(db.String(255), nullable=True, comment='专业')
    degree = db.Column(db.String(255), nullable=True, comment='学历')
    skill = db.Column(db.Text, nullable=True, comment='技能')
    work_exp = db.Column(db.String(255), nullable=True, comment='工作经历')
    emergency_contacts = db.Column(db.String(255), nullable=True, comment='紧急联系人')
    contacts_phone = db.Column(db.String(255), nullable=True, comment='联系人电话')
    status = db.Column(db.String(1), nullable=True, default='0', comment='帐号状态（0正常 1停用）')
    del_flag = db.Column(db.String(1), nullable=True, default='0', comment='删除标志（0代表存在 2代表删除）')
    create_dept = db.Column(db.BigInteger, nullable=True, comment='创建部门')
    create_by = db.Column(db.BigInteger, nullable=True, comment='创建者')
    create_time = db.Column(db.DateTime, nullable=True, comment='创建时间')
    update_by = db.Column(db.BigInteger, nullable=True, comment='更新者')
    update_time = db.Column(db.DateTime, nullable=True, comment='更新时间')
    remark = db.Column(db.String(500), nullable=True, comment='备注')

    def __repr__(self):
        return f"<AppUserDetail {self.detail_id} {self.name} {self.app_user_name}>"
